package com.example.demo.mapper;

import com.example.demo.model.Userinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
//     @ResultMap("BaseMap")
     @Select("select * from userinfo")
//     Userinfo queryUserinfos();
      List<Userinfo> queryUserinfos();


     @Select("select * from userinfo where id = #{value}")
     Userinfo queryUserinfos1(Integer id);

     @Select("select * from userinfo where id = #{id} and name = #{name}")
     Userinfo queryUserinfos2(Integer id,String name);

     @Insert("insert into userinfo (id) values(#{id})")
     Integer insert(Integer id);

     @Insert("insert into userinfo (id,name) values(#{id},#{name})")
     Integer insert1(Integer id,String name);
     @Options(useGeneratedKeys = true,keyProperty = "id")
     @Insert("insert into userinfo (id,age,name,password,gender,phone) values(#{userinfo.id},#{userinfo.age},#{userinfo.name},#{userinfo.password},#{userinfo.gender},#{userinfo.phone})")
     Integer insert2(@Param("userinfo") Userinfo userinfo);

//     @Insert("insert into userinfo (id,name,password,gender,phone) values(#{id},#{age},#{name},#{password},#{gender},#{phone})")
//     Integer insert3(@Param("userinfo") Userinfo userinfo);
//
//     @Options(useGeneratedKeys = true,keyProperty = "id")
//     @Insert("insert into userinfo (id,name,password,gender,phone) values(#{id},#{age},#{name},#{password},#{gender},#{phone})")
//     Integer insert4(Userinfo userinfo);
     @Delete("delete from userinfo where id = #{id}")
     Integer delete(Integer id);

     @Update("update userinfo set password = #{password} where id = #{id}")
    void update(Userinfo userInfo);

//法1：
     @Select("select id,name,age,gender,phone,delete_flag as deleteFlag,create_time as createTime, update_time as updateTime from userinfo")
     List<Userinfo> queryUserinfos9();
//法2：
     @Results(id ="BaseMap",value = {
             @Result(column = "delete_flag",property = "deleteFlag"),
             @Result(column ="create_time" ,property = "createTime"),
             @Result(column ="update_time" ,property = "updateTime"),
     })
     @Select("select * from userinfo")
     List<Userinfo> queryUserinfos8();


     //法3：

     @Results(id ="BaseMap",value = {
             @Result(column = "delete_flag",property = "deleteFlag"),
             @Result(column ="create_time" ,property = "createTime"),
             @Result(column ="update_time" ,property = "updateTime"),
     })
     @ResultMap("BaseMap")
     @Select("select * from userinfo")
     List<Userinfo> queryUserinfos6();


     @Select("select * from userinfo where name = #{name} and password = #{password}")
     Userinfo queryUserinfos110(String name,String password);


     @Select("select * from userinfo where name = '${name}' and password = '${password}'")
     List<Userinfo> queryUserinfos111(String name,String password);

     @Select("select * from userinfo order by id ${order}")
     List<Userinfo> queryUserInfoByOrder(String order);

     @Select("select * from userinfo where name like '%${name}%'")
     List<Userinfo> queryUserInfoLike(String name);

     @Select("select * from userinfo where name like concat('%',#{name},'%')")
     List<Userinfo> queryUserInfoLike1(String name);

     @Insert("<script>insert into userinfo (id,name, " +
             "<if test ='age != null'>age,</if>" +
             "gender,password,phone) " +
             "values (#{id},#{name}, " +
             "<if test='age != null'>#{age},</if> " +
             "#{gender},#{password},#{phone})" +
             "</script>")
     Integer insertByCondition(Userinfo userinfo);


}
